package com.googlecode.animator.core
{
	import com.googlecode.animator.controller.AddCameraCommand;
	import com.googlecode.animator.controller.AddCameraProxiesCommand;
	import com.googlecode.animator.controller.AddDefaultCamerasCommand;
	import com.googlecode.animator.controller.AddDefaultViewportsCommand;
	import com.googlecode.animator.controller.AddObject3DCommand;
	import com.googlecode.animator.controller.AddSceneCommand;
	import com.googlecode.animator.controller.AddViewportCommand;
	import com.googlecode.animator.controller.AppStartupCommand;
	import com.googlecode.animator.controller.CameraZoomChangedCommand;
	import com.googlecode.animator.controller.DeleteObject3DCommand;
	import com.googlecode.animator.controller.MakeFilePathsAbsoluteCommand;
	import com.googlecode.animator.controller.NewProjectCommand;
	import com.googlecode.animator.controller.Object3DReleasedCommand;
	import com.googlecode.animator.controller.Object3DSelectedCommand;
	import com.googlecode.animator.controller.OpenProjectCommand;
	import com.googlecode.animator.controller.PackageProjectCommand;
	import com.googlecode.animator.controller.PreviewProjectCommand;
	import com.googlecode.animator.controller.ResetProjectCommand;
	import com.googlecode.animator.controller.SaveProjectCommand;
	import com.googlecode.animator.controller.SetMaterialTransportControlsCommand;
	import com.googlecode.animator.controller.SetSavePathCommand;
	import com.googlecode.animator.controller.SetStageSizeCommand;
	import com.googlecode.animator.controller.TimelineAddGlobalMarkerCommand;
	import com.googlecode.animator.controller.TimelineAddHideMarkerCommand;
	import com.googlecode.animator.controller.TimelineAddKeyframeCommand;
	import com.googlecode.animator.controller.TimelineCalculateTweensCommand;
	import com.googlecode.animator.controller.TimelineGlobalMarkerMovedCommand;
	import com.googlecode.animator.controller.TimelineHideMarkerMovedCommand;
	import com.googlecode.animator.controller.TimelineKeyframeMovedCommand;
	import com.googlecode.animator.controller.TimelineRemoveGlobalMarkerCommand;
	import com.googlecode.animator.controller.TimelineRemoveHideMarkerCommand;
	import com.googlecode.animator.controller.TimelineRemoveKeyframeCommand;
	import com.googlecode.animator.controller.TimelineScrubObjects3DCommand;
	import com.googlecode.animator.controller.TimelineSetCurrentTimeIntervalCommand;
	import com.googlecode.animator.controller.TimelineSetKeyframePositionCommand;
	import com.googlecode.animator.controller.UpdateMaterialCommand;
	import com.googlecode.animator.controller.UpdatePropertyCommand;
	import com.googlecode.animator.controller.UpdateViewportCommand;
	import com.googlecode.animator.data.Notifications;
	
	import mx.core.Application;
	
	import org.puremvc.as3.multicore.patterns.facade.Facade;
	
	/**
	 * PureMVC Facade implementation for 3DAnimator
	 * 
	 * Implements the Singleton interface.
	 *  
	 * @author Martin
	 */
	public class Animator3DFacade extends Facade
	{
		public function Animator3DFacade(key:String)
		{
			super(key);
		}
		
		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		/* public static function start(appRef:Application):void
		{
			getInstance().sendNotification(Notifications.APP_START, appRef);
		}
		
		static public function getInstance():Animator3DFacade
		{
			if(instance == null)
			{
				instance = new Animator3DFacade();
			}
			
			return instance as Animator3DFacade;
		} */
		
		/**
		 * Return multiton instance. 
		 * @return 
		 */
		public static function getInstance(key:String):Animator3DFacade
		{
			if(!hasCore(key))
			{
				instanceMap[key] = new Animator3DFacade(key);
			}
			
			return instanceMap[key] as Animator3DFacade;
		}


		/**
		 * Application startup function.
		 * @param appRef Reference to the main application instance.
		 */
		public static function start(appKey:String, appRef:Application):void
		{
			getInstance(appKey).sendNotification(Notifications.APP_START, appRef);
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			
			// startup command
			// Note: No Mediators registered at this stage
			registerCommand(Notifications.APP_START, AppStartupCommand);
			
			// add the 3d scene command
			registerCommand(Notifications.ADD_SCENE_MODEL, AddSceneCommand);
			
			// launch project macro command
			registerCommand(Notifications.NEW_PROJECT, NewProjectCommand);
			
			// launch project macro command
			//registerCommand(Notifications.PROJECT_LAUNCH_MACRO_COMMAND, ProjectLaunchMacroCommand);
			
			// reset project command
			registerCommand(Notifications.RESET_PROJECT, ResetProjectCommand);
			
			// open project command
			registerCommand(Notifications.OPEN_PROJECT, OpenProjectCommand);
			
			// save project command
			registerCommand(Notifications.SAVE_PROJECT, SaveProjectCommand);
			
			// save project command
			registerCommand(Notifications.SET_SAVE_PATH, SetSavePathCommand);
			
			// add camera command
			registerCommand(Notifications.ADD_CAMERA_MODEL, AddCameraCommand);
			
			// add default cameras command
			registerCommand(Notifications.ADD_DEFAULT_CAMERAS_MODEL, AddDefaultCamerasCommand);
			
			// add default viewports command
			registerCommand(Notifications.ADD_DEFAULT_VIEWPORTS, AddDefaultViewportsCommand);
			
			// add camera proxies command
			registerCommand(Notifications.ADD_CAMERA_PROXIES_MODEL, AddCameraProxiesCommand);
			
			// add object3D command
			registerCommand(Notifications.ADD_OBJECT3D_MODEL, AddObject3DCommand);
			
			// delete object3D command
			registerCommand(Notifications.DELETE_OBJECT3D_MODEL, DeleteObject3DCommand);
			
			// mouse up on a DisplayObject3D command
			registerCommand(Notifications.MOUSE_UP_OBJECT3D, Object3DReleasedCommand);
			
			// object3D selected command
			registerCommand(Notifications.OBJECT3D_SELECTED_MODEL, Object3DSelectedCommand);
			
			// add viewport command
			registerCommand(Notifications.ADD_VIEWPORT_MODEL, AddViewportCommand);
			
			// update camera settings commands
			registerCommand(Notifications.UPDATE_CAMERA_SETTINGS_MODEL, CameraZoomChangedCommand);
			
			// add keyframe command
			registerCommand(Notifications.TIMELINE_ADD_KEYFRAME, TimelineAddKeyframeCommand);
			
			// remove keyframe command
			registerCommand(Notifications.TIMELINE_REMOVE_KEYFRAME, TimelineRemoveKeyframeCommand);
			
			// keyframe moved command
			registerCommand(Notifications.TIMELINE_KEYFRAME_MOVED, TimelineKeyframeMovedCommand);
			
			// set keyframe position information
			registerCommand(Notifications.TIMELINE_SET_KEYFRAME_POSITION, TimelineSetKeyframePositionCommand);
			
			// keyframe moved command
			registerCommand(Notifications.TIMELINE_CALCULATE_TWEENS, TimelineCalculateTweensCommand);
			
			// set current time interval
			registerCommand(Notifications.TIMELINE_SET_CURRENT_TIME_INTERVAL, TimelineSetCurrentTimeIntervalCommand);
			
			// move objects3D in scene
			registerCommand(Notifications.TIMELINE_SCRUB_OBJECTS3D, TimelineScrubObjects3DCommand);
			
			// add hide marker command
			registerCommand(Notifications.TIMELINE_ADD_HIDE_MARKER, TimelineAddHideMarkerCommand);
			
			// remove hide marker command
			registerCommand(Notifications.TIMELINE_REMOVE_HIDE_MARKER, TimelineRemoveHideMarkerCommand);
			
			// update hide marker command
			registerCommand(Notifications.TIMELINE_HIDE_MARKER_MOVED, TimelineHideMarkerMovedCommand);
			
			// add global marker command
			registerCommand(Notifications.ADD_GLOBAL_MARKER, TimelineAddGlobalMarkerCommand);
			
			// remove global marker command
			registerCommand(Notifications.TIMELINE_REMOVE_GLOBAL_MARKER, TimelineRemoveGlobalMarkerCommand);
			
			// update global marker command
			registerCommand(Notifications.TIMELINE_GLOBAL_MARKER_MOVED, TimelineGlobalMarkerMovedCommand);
			
			// properties change property command
			registerCommand(Notifications.UPDATE_PROPERTY_MODEL, UpdatePropertyCommand);
			
			// properties change property command
			//registerCommand(Notifications.OBJECT3D_SWF_LOADED, PropertiesSWFLoadedCommand);
			
			// properties change material command
			registerCommand(Notifications.UPDATE_OBJECT3D_MATERIAL_MODEL, UpdateMaterialCommand);
			
			// update viewport command
			registerCommand(Notifications.VIEWPORT_UPDATED_MODEL, UpdateViewportCommand);
			
			// package the project command
			registerCommand(Notifications.PACKAGE_PROJECT, PackageProjectCommand);
			
			// make all file paths absolute command
			registerCommand(Notifications.MAKE_FILE_PATHS_ABSOLUTE, MakeFilePathsAbsoluteCommand);
			
			// set stage size
			registerCommand(Notifications.SET_STAGE_SIZE_MODEL, SetStageSizeCommand);
			
			// sets wheher or not flvs or swfs have transport controls
			registerCommand(Notifications.SET_MATERIAL_TRANSPORT_CONTROLS_MODEL, SetMaterialTransportControlsCommand);
			
			// preview the project
			registerCommand(Notifications.PREVIEW_PROJECT, PreviewProjectCommand);
		}

	}
}